package toDo.pack;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class ToDoActivity extends Activity {
	String[] user,pass;
	Button login;
	Button register;
	EditText username, password; 
	TextView error;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        user = new String[10];
        pass = new String[10];
        user[0] = "dlong";
        pass[0] = "password";
        login = (Button) findViewById(R.id.blogin);
        register = (Button) findViewById(R.id.breg);
        username = (EditText) findViewById(R.id.tUsername);
        password = (EditText) findViewById(R.id.tPassword);
        error = (TextView) findViewById(R.id.tError);
        
        login.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String usertemp = username.getText().toString();
				String passtemp = password.getText().toString();
				boolean ver = verify(usertemp,passtemp);
				
				if(ver = false)
					error.setText("Invalid Username or Password");
				if(ver = true)
					error.setText("Login Correct");
			}
		});
        register.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String usertemp = username.getText().toString();
				String passtemp = password.getText().toString();
				if(usertemp.equals("") || passtemp.equals(""))
					error.setText("No username or password was entered");
				else{
					int count = 0;
					while(user[count] != "") count++;
					
					user[count] = usertemp;
					pass[count] = passtemp;
				}
			}
		});
        
    }
    public boolean verify(String username, String password){
    	for(int i = 0; i < user.length;i++){
    		if(user[i] .equals(username)){
    			if(pass[i] .equals(password)){
    				//error.setText("Login Correct");
    				return true;
    			}
    		}
    	}
    	//error.setText("Invalid Username or Password");
    	return false;
    }
}